var userName = null;
var userRole = null;
var userStatus = null;
var saveBtn = null;
var backBtn = null;

$(function(){
	userName = $("#UserName");
	userRole = $("#UserRole");
	userStatus = $("#UserStatus");
	saveBtn = $("#save");
	backBtn = $("#back");
	userName.next().html("*");
	userRole.next().html("*");
	userStatus.next().html("*");

	


	
	userRole.on("focus",function(){
		console.log("1111")
		validateTip(userRole.next(),{"color":"#666666"},"* 请选择用户角色",false);
	}).on("blur",function(){
		console.log(userRole.val())
		if(userRole.val() != null && userRole.val() > 0){
			validateTip(userRole.next(),{"color":"green"},imgYes,true);
		}else{
			validateTip(userRole.next(),{"color":"red"},imgNo+" 请重新选择用户角色",false);
		}
		
	});

	userStatus.on("focus",function(){
		console.log("1111")
		validateTip(userStatus.next(),{"color":"#666666"},"* 请选择用户状态",false);
	}).on("blur",function(){
		console.log(userStatus.val())
		if(userStatus.val() != null && userStatus.val() >= 0){
			validateTip(userStatus.next(),{"color":"green"},imgYes,true);
		}else{
			validateTip(userStatus.next(),{"color":"red"},imgNo+" 请重新选择用户状态",false);
		}

	});
	
	saveBtn.on("click",function(){
		userRole.blur();
		userStatus.blur();
		if( userRole.attr("validateStatus") == "true"
			&& userStatus.attr("validateStatus") == "true"){
			if(confirm("是否确认要提交数据？")){
				$("#userForm").submit();
			}
		}
	});
	
	backBtn.on("click",function(){
		//alert("modify: "+referer);
		if(referer != undefined 
			&& null != referer 
			&& "" != referer
			&& "null" != referer
			&& referer.length > 4){
		 window.location.href = referer;
		}else{
			history.back(-1);
		}
	});
});